@extends('admin.layouts.content')
@section('content')

    <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
        <div class="layui-form-item">
            <label class="layui-form-label">上级功能</label>
            <div class="layui-input-block">
                <select name="parent_id" lay-verify="required" class="layui-input">
                    @foreach($selectOptions as $optionKey => $optionValue)
                        <option value="{{$optionKey}}">{!! $optionValue !!}</option>
                    @endforeach
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">功能名称</label>
            <div class="layui-input-block">
                <input type="text" name="title" lay-verify="required" placeholder="请输入菜单名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">功能标识</label>
            <div class="layui-input-block">
                <input type="text" name="name" placeholder="请输入菜单标识" autocomplete="off" class="layui-input">
            </div>
        </div>
        <input type="hidden" name="menuType" value="1" />

        <!--
        <div class="layui-form-item">
            <label class="layui-form-label">菜单类型</label>
            <div class="layui-input-block">
                <select name="menuType" lay-verify="required" class="layui-input">
                    <option value="0">模块</option>
                    <option value="1">功能</option>
                    <option value="2">操作按钮</option>
                </select>
            </div>
        </div>
        -->

        <div class="layui-form-item">
            <label class="layui-form-label">功能路径</label>
            <div class="layui-input-block">
                <input type="text" name="uri" lay-verify="required" placeholder="请输入功能路径" autocomplete="off" class="layui-input">
            </div>
        </div>

{{--        <div class="layui-form-item">--}}
{{--            <label class="layui-form-label">显示图标</label>--}}
{{--            <div class="layui-input-inline">--}}
{{--                <input type="text" id="iconPicker" name="icon" lay-filter="iconPicker" class="hide" value="fa-address-book">--}}
{{--            </div>--}}
{{--        </div>--}}

{{--        <div class="layui-form-item">--}}
{{--            <label class="layui-form-label">权限验证</label>--}}
{{--            <div class="layui-input-block">--}}
{{--                <select name="authority" class="layui-input">--}}
{{--                    <option value="">不验证</option>--}}
{{--                    <option value="user:view">View::user</option>--}}
{{--                </select>--}}
{{--            </div>--}}
{{--        </div>--}}


        <div class="layui-form-item layui-hide">
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
            <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
        </div>
    </div>

@endsection
@section('script')
<script>
    layui.use(['iconPickerFa', 'jquery', 'form'], function(){
        var $ = layui.$ ,form = layui.form;
        var iconPickerFa = layui.iconPickerFa;

        iconPickerFa.render({
            // 选择器，推荐使用input
            elem: '#iconPicker',
            // fa 图标接口
            url: "/layuiadmin/font-awesome-4.7.0/less/variables.less",
            // 是否开启搜索：true/false，默认true
            search: true,
            // 是否开启分页：true/false，默认true
            page: true,
            // 每页显示数量，默认12
            limit: 30,
            // 点击回调
            click: function (data) {
                console.log(data);
            },
            // 渲染成功后的回调
            success: function (d) {
                console.log(d);
            }
        });

        //监听提交
        form.on('submit(layuiadmin-app-form-submit)', function(data){
            var field = data.field; //获取提交的字段
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.ajax({
                url: "{{url('admin/menu/store')}}",
                method: "POST",
                dataType : "json",
                data: data.field,
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                success: function (json) {
                    parent.layui.table.reload('LAY-app-content-list'); //重载表格
                    parent.layer.close(index); //再执行关闭
                },
                error: function () {
                    layer.msg('系统错误');
                }
            });

        });
    })
</script>
@endsection
